﻿using Sidvall.WorkItemManager.Workflow;

namespace Sidvall.WorkItemManager.Data.Model.EntityManagers
{
    public partial class WorkItemTypeManager<TEntity, TList>
    {
        public IWorkItemProvider GetWorkItemProvider(IWorkItemType workItemType, IWorkItem workItem)
        {
            if (workItemType == null)
                return null;
            var type = Sidvall.SystemContext.Current.TypeCache.GetType(workItemType.Codename);
            var item = Sidvall.SystemContext.Current.CodeManager.CreateInstance(type) as IWorkItemProvider;
            if ((item != null) && (workItem != null))
            {
                item.Context = workItem.WorkItemContext;
                item.ExecutionContext = workItem.ExecutionContext;
            }
            return item;
        }
    }
}